package tk.mybatis.springboot.model;

import java.io.Serializable;

import tk.mybatis.springboot.wexin.util.DateUtils;

public class Message implements Serializable {

	private static final long serialVersionUID = -7575041938552426008L;

	/**
	 * 状态
	 */
	private String code;

	/**
	 * 信息
	 */
	private String msg;

	/**
	 * 时间
	 */
	private String time;

	/**
	 * 数据
	 */
	private Object data;

	public Message(String code, String message, String time) {
		super();
		this.code = code;
		this.msg = message;
		this.time = time;
	}

	/**
	 * 返回成功信息
	 * 
	 * @param data
	 * @return
	 */
	public static Message success() {
		Message msg = new Message("0000", "获取数据成功", DateUtils.getNowTime_6());
		return msg;
	}

	/**
	 * 返回固定消息的成功信息
	 * 
	 * @param data
	 * @return
	 */
	public static Message success(Object data) {
		Message msg = new Message("0000", "获取数据成功", DateUtils.getNowTime_6());
		msg.setData(data);
		return msg;
	}

	/**
	 * 展示成功信息，包含数据
	 * 
	 * @param message
	 * @param data
	 * @return
	 */
	public static Message success(String message, Object data) {
		Message msg = new Message("0000", message, DateUtils.getNowTime_6());
		msg.setData(data);
		return msg;
	}

	/**
	 * 失败的信息及通用数据
	 * @param message
	 * @param data
	 * @return
	 */
	public static Message fail(String message, Object data) {
		Message msg = new Message("4399", message, DateUtils.getNowTime_6());
		msg.setData(data);
		return msg;
	}

	/**
	 * 返回失败信息和失败原因
	 * 
	 * @param message
	 * @return
	 */
	public static Message fail(String message) {
		return new Message("4399", message, DateUtils.getNowTime_6());
	}

	/**
	 * 返回错误信息和错误原因
	 * 
	 * @param message
	 * @return
	 */
	public static Message error(String message) {
		return new Message("9999", message, DateUtils.getNowTime_6());
	}

	public static Message errorCode(String code) {
		return new Message("code", "请求失败", DateUtils.getNowTime_6());
	}
	
	/**
	 * 返回固定信息的错误
	 *
	 * @return
	 */
	public static Message error() {
		return new Message("9999", "服务器错误，我们已记录并将尽快处理", DateUtils.getNowTime_6());
	}

	/**
	 * 成功后的消息
	 * @return
	 */
	public static Message success(String message) {
		return new Message("0000", message, DateUtils.getNowTime_6());
	}

	public String getCode() {
		return code;
	}

	public void setCode(String code) {
		this.code = code;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}

	public String getTime() {
		return time;
	}

	public void setTime(String time) {
		this.time = time;
	}

	public Object getData() {
		return data;
	}

	public void setData(Object data) {
		this.data = data;
	}

}

